var Task = new Class({
	id:false,
	
	select:function(id) {
		if(this.id && id == this.task_id) {return;}
		
		// if selected task is member of another project - select project first
		if(typeof projectid != "undefined" && project != projectid) {
			project_select(projectid, id);
			return;
		}
		
		tasksselected.each(function(e) { $('row_'+e).removeClass('selected'); });
		if(currentTask) {lastTask = currentTask;}
		
		currentId = id;
		currentTask = $t(id);
		currentRow = $('row_'+currentId);
		
		$(currentId+'_t_feature').addEvent('keyup', function(e){ 
			if(currentRow.hasClass('block') && e.target.value === '') { currentRow.removeClass('block');} 
			if(!currentRow.hasClass('block') && e.target.value !== '') { currentRow.addClass('block').removeClass('empty');}
		});
		
		// if the current Task is the last task in the tasklist - add a new task
		if (currentTask.index == tasklist.length - 1) { newTask(currentId); }
		
		// if shift key is pressed select all tasks between
		if($defined(event) && event.shift && lastTask) {
			
			tasksselected = [];
			var select = false;
			var selfrom = false;
			var seltill = false;
			
			if(Number(currentTask.index) > Number(lastTask.index)) {
				selfrom = lastTask.task_id;
				seltill = currentTask.task_id;
			} else {
				selfrom = currentTask.task_id;
				seltill = lastTask.task_id;
			}
			
			tasklist.each( function(e,i) {
				if(e.task_id == selfrom) { select = true; }
				if(select) { tasksselected.push(e.task_id); }
				if(e.task_id == seltill) { select=false; return; }
			});
		
		// if ctrl or apple key is pressed
		} else if ($defined(event) && event[controlkey]) {
			tasksselected.push(currentTask.task_id);
		
		// if no key press is present
		} else {
			tasksselected = [currentTask.task_id];	
		}
		
		// mark all selected rows
		tasksselected.each(function(e) {
			$('row_'+e).addClass('selected');
		});
	
		updateContextMenu();
		BC.broadcastMessage('_task_select',id);
	},
	
	task_insert_date:function() {
	
	},
	
	task_insert_time:function() {
		
	},
	
	task_setReady:function (e) {
	var taskid = e.id.substr(3);
	task_select(taskid);
	
	if(currentTask.t_elapsed === 0) {
		updateTask(currentTask, 't_elapsed', (currentTask.t_currest > 61 ? currentTask.t_currest : 61), s2h);
		updateField($(taskid+'_t_elapsed'));
	}
	
	$(taskid+'_t_currest').value = s2h(currentTask.t_elapsed);
	updateField($(taskid+'_t_currest'));
	
	tasklist_updateSummary();
}
});
